package com.tudouji.project.harvest.controller;

import com.tudouji.common.utils.poi.ExcelUtil;
import com.tudouji.framework.aspectj.lang.annotation.Log;
import com.tudouji.framework.aspectj.lang.enums.BusinessType;
import com.tudouji.framework.web.controller.BaseController;
import com.tudouji.framework.web.domain.AjaxResult;
import com.tudouji.framework.web.page.TableDataInfo;
import com.tudouji.project.harvest.domain.Qaresult;
import com.tudouji.project.harvest.service.IQaresultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 质检结果Controller
 *
 * @author tudouji
 * @date 2021-05-13
 */
@RestController
@RequestMapping("/harvest/qaresult")
public class QaresultController extends BaseController
{
    @Autowired
    private IQaresultService qaresultService;

    /**
     * 查询质检结果列表
     */
    @PreAuthorize("@ss.hasPermi('harvest:qaresult:list')")
    @GetMapping("/list")
    public TableDataInfo list(Qaresult qaresult)
    {
        startPage();
        List<Qaresult> list = qaresultService.selectQaresultList(qaresult);
        return getDataTable(list);
    }

    /**
     * 导出质检结果列表
     */
    @PreAuthorize("@ss.hasPermi('harvest:qaresult:export')")
    @Log(title = "质检结果", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Qaresult qaresult)
    {
        List<Qaresult> list = qaresultService.selectQaresultList(qaresult);
        ExcelUtil<Qaresult> util = new ExcelUtil<Qaresult>(Qaresult.class);
        return util.exportExcel(list, "qaresult");
    }

    /**
     * 获取质检结果详细信息
     */
    @PreAuthorize("@ss.hasPermi('harvest:qaresult:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(qaresultService.selectQaresultById(id));
    }

    /**
     * 新增质检结果
     */
    @PreAuthorize("@ss.hasPermi('harvest:qaresult:add')")
    @Log(title = "质检结果", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Qaresult qaresult)
    {
        return toAjax(qaresultService.insertQaresult(qaresult));
    }

    /**
     * 修改质检结果
     */
    @PreAuthorize("@ss.hasPermi('harvest:qaresult:edit')")
    @Log(title = "质检结果", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Qaresult qaresult)
    {
        return toAjax(qaresultService.updateQaresult(qaresult));
    }

    /**
     * 删除质检结果
     */
    @PreAuthorize("@ss.hasPermi('harvest:qaresult:remove')")
    @Log(title = "质检结果", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(qaresultService.deleteQaresultByIds(ids));
    }

    /**
     * 获取对应质检相结果
     */
    @GetMapping("/getQaResultWithType")
    public AjaxResult getQaResultWithType(String guid, Integer type) {
        return qaresultService.getQaResultWithType(guid, type);
    }

}
